//
//  HomeController.m
//  Safflower
//
//  Created by 袁亮 on 2016/11/28.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "HomeController.h"
#import "HomeView.h"
#import "HomeDataCenter.h"
#import "PushTaskController.h"
#import "FriendListController.h"
#import "SettingController.h"
#import "MsgCenterController.h"
#import "TaskListController.h"

@interface HomeController () <HomeViewDelegate>

@property (nonatomic, strong) HomeView *homeView;
@property (nonatomic, strong) HomeDataCenter *dataCenter;

@end

@implementation HomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dataCenter = [[HomeDataCenter alloc]init];
    
    [self makeHomeView];
    
    [self loadMenuData];
    
    [self loadCarouselData];
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self loadUserInfo];
}

- (void)loadMenuData
{
    __weak __typeof(self) weakSelf = self;
    [_dataCenter fetchHomeMenuData:^(NSArray *data) {
        weakSelf.homeView.menuData = data;
    }];
}

- (void)loadCarouselData
{
    [_dataCenter fetchHomeCarouselData:^(NSArray *data, NSString *error) {
        if (error == nil) {
            [_homeView loadCarouselData:data];
        }
    }];
}

- (void)loadUserInfo
{
    UserModel *user = [UserManager fetchUserInfo];
    [_homeView refreshUserData:user];
}

- (void)makeHomeView
{
    _homeView = [HomeView new];
    _homeView.delegate = self;
    _homeView.layer.masksToBounds = YES;
    _homeView.layer.borderWidth = 2;
    _homeView.layer.borderColor = [RGB(0, 0, 0) CGColor];
    [self.view addSubview:_homeView];
    [_homeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
    }];
}

- (void)clickMessage
{
    MsgCenterController *msgCenterController = [[MsgCenterController alloc]init];
    
    [self presentViewController:msgCenterController animated:NO completion:nil];
}

- (void)didSelectPushTask
{
    PushTaskController *pushTaskController = [[PushTaskController alloc]init];
    
    [self presentViewController:pushTaskController animated:NO completion:nil];
}

- (void)didSelectTaskList
{
    TaskListController *taskListController = [[TaskListController alloc]init];
    BaseNavigationController *taskNavigation = [[BaseNavigationController alloc]initWithRootViewController:taskListController];
    [self presentViewController:taskNavigation animated:NO completion:nil];
}

- (void)didSelectFriendList
{
    FriendListController *friendListController = [[FriendListController alloc]init];
    
    [self presentViewController:friendListController animated:NO completion:nil];
}

- (void)didSelectSetting
{
    SettingController *settingController = [[SettingController alloc]init];
    
    [self presentViewController:settingController animated:NO completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
